package cn.com.utt.unms.controller;

import java.security.Principal;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import cn.com.utt.common.vo.RestResult;
import cn.com.utt.common.vo.User;
import cn.com.utt.unms.service.AddressService;
import cn.com.utt.unms.service.UserRecordService;

@RestController
@RequestMapping("v1/homes")
public class HomeController {
	@Autowired
	private UserRecordService onlineDeviceService;
	
	@Autowired
	private AddressService addressService;
	
	@RequestMapping(value="currentmessage",method={RequestMethod.POST})
	public Map<String, Object> currentmessage(Principal principal){
		RestResult result = new RestResult();
		Authentication authentication = (Authentication) principal;
		User user = (User)authentication.getPrincipal();
		Map<String, Object> res=onlineDeviceService.queryDevices(user.getId(),user.getGroupId());
		result.put("res", res);
		return result.toJsonObject();
	}
	
	@RequestMapping(value="homemap",method={RequestMethod.POST})
	public Map<String, Object> homemap(Principal principal){
		RestResult result = new RestResult();
		Authentication authentication = (Authentication) principal;
		User user = (User)authentication.getPrincipal();
		List<Map<String, Object>> res=addressService.map(user.getGroupId());
		result.put("res", res);
		return result.toJsonObject();
	}

}
